<template>
  <div class="baiduUe">
    <div class="outmain ba_f heighthv pad_20 bor_rad5">
      <div class="shuju_title mar_b20">
        <div class="shuju_title_text">
          <span v-if="type=='1'">创建满减优惠券</span>
          <span v-if="type=='2'">创建折扣优惠券</span>
          <span v-if="type=='3'">创建商品兑换券</span>
        </div>
      </div>
      <div class="mar_t20 flex-bet flex-y-top">
        <div class="flex-g-1">
          <el-form ref="form" :model="form" :rules="rules" label-width="180px">
            <el-form-item label="排序">
              <el-input v-model="form.sort" placeholder="请输入排序"></el-input>
            </el-form-item>
            <el-form-item label="优惠券名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入优惠券名称"></el-input>
            </el-form-item>
            <el-form-item label="活动时间" :required="true">
              <el-date-picker v-model="timeData" type="datetimerange" align="right" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['08:00:00', '23:59:59']"></el-date-picker>
            </el-form-item>
            <el-form-item label="发放总量" :required="true">
              <el-input v-model="form.stock" placeholder="请输入发放总量"></el-input>
            </el-form-item>
            <el-form-item label="使用门槛" :required="true">
              <div class="flex">
                <div>
                  <el-radio v-model="form.isFull" label="1">无门槛</el-radio>
                </div>
                <div class="time_item mar_l20">
                  <el-radio v-model="form.isFull" label="2">有门槛</el-radio>
                  <span v-show="form.isFull=='2'">
                    <span class="mar_r10">订单满</span>
                    <el-input-number v-model="form.fullMoney" v-if="form.isFull=='1'" disabled controls-position="right" :min="1" :max="1000000"></el-input-number>
                    <el-input-number v-model="form.fullMoney" v-else controls-position="right" :min="1" :max="1000000"></el-input-number>
                    <span class="mar_l10">元才可用</span>
                  </span>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="优惠内容" :required="true" v-if="type=='1' || type=='2'">
              <div class="time_item">
                <span class="mar_r10" v-if="type=='1'">减免</span>
                <span class="mar_r10" v-if="type=='2'">打</span>
                <el-input-number v-if="type=='1'" v-model="form.money" controls-position="right" :min="1" :max="1000000"></el-input-number>
                <el-input-number v-if="type=='2'" v-model="form.discount" controls-position="right" :min="0.1" :max="1000000"></el-input-number>
                <span class="mar_l10" v-if="type=='1'">元</span>
                <span class="mar_l10" v-if="type=='2'">折</span>
              </div>
            </el-form-item>
            <el-form-item label="适用门店" :required="true">
              <el-radio-group v-model="form.storeType">
                <el-radio label="1">仅本店可用</el-radio>
                <el-radio label="2"  v-if="type!='3'">全店通用</el-radio>
                <el-radio label="3">指定门店可用</el-radio>
              </el-radio-group>
              <div v-show="form.storeType=='3'">
                <el-scrollbar>
                  <div class="recordBox">
                    <el-table ref="multipleTable" :data="shopTable" tooltip-effect="dark" style="width: 100%">
                      <el-table-column prop="name" label="门店名称"></el-table-column>
                      <el-table-column prop="address" label="门店地址"></el-table-column>
                      <el-table-column label="操作">
                        <template slot-scope="scope">
                          <div class="textbutton">
                            <el-button size="mini" type="text" @click="open2(scope.row,scope.$index)" class>删除</el-button>
                          </div>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </el-scrollbar>
                <div class="addgoods textbutton">
                  <i class="el-icon-plus subjectcolor2"></i>
                  <el-button type="text" class @click="addshop(shopTable)">添加门店</el-button>
                </div>
              </div>
              <div class="yb_margin lh16">全店通用、指定门店可用不适用于门店模式三</div>
            </el-form-item>
            <el-form-item label="平台补贴">
              <el-input v-model="form.subsidy" placeholder="请输入平台补贴"></el-input>
              <span class="mar_l10">元</span>
            </el-form-item>
            <el-form-item label="适用商品" :required="true"  v-if="type=='1' || type=='2'">
              <el-radio-group v-model="form.goodsType">
                <el-radio label="1">全部商品可用</el-radio>
                <el-radio label="2">部分商品可用</el-radio>
                <el-radio label="3">部分商品不可用</el-radio>
                <el-radio label="4">指定商品分类</el-radio>
              </el-radio-group>
              <div class="mar_t10" v-show="form.goodsType=='4'">
                <div class="flex">
                  <div>外卖分类：</div>
                  <el-select v-model="goodsArr" clearable multiple filterable allow-create placeholder="请选择外卖商品分类">
                    <el-option v-for="item in typeOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
                  </el-select>
                </div>
                <div class="flex mar_t20" v-if="form.useType.indexOf('2')>-1 || form.useType.indexOf('3')>-1">
                  <div>店内分类：</div>
                  <el-select v-model="goodsArr2" clearable multiple filterable allow-create placeholder="请选择店内商品分类">
                    <el-option v-for="item in typeOptions2" :key="item.id" :label="item.name" :value="item.id"></el-option>
                  </el-select>
                </div>
              </div>
              <div class v-show="(form.goodsType=='2' || form.goodsType=='3') && form.useType.indexOf('1')>-1">
                <div>外卖商品：</div>
                <el-scrollbar>
                  <div class="recordBox">
                    <el-table ref="multipleTable" :data="tableData3" tooltip-effect="dark" style="width: 100%" class="tablecenter">
                      <el-table-column prop="name" label="商品">
                        <template slot-scope="scope">
                          <div class="flex">
                            <div class="flex-g-0">
                              <el-image style="width: 60px;height: 60px;border-radius: 10px;" :src="scope.row.icon" fit="cover"></el-image>
                            </div>
                            <div class="flex-g-1 t_l">
                              <div class="mar_l10">{{scope.row.name}}</div>
                            </div>
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="price" label="价格"></el-table-column>
                      <el-table-column prop="stock" label="库存"></el-table-column>
                      <el-table-column label="操作">
                        <template slot-scope="scope">
                          <div class="textbutton">
                            <el-button size="mini" type="text" @click="open1(scope.row,scope.$index)" class>删除</el-button>
                          </div>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </el-scrollbar>
                <div class="addgoods textbutton">
                  <i class="el-icon-plus subjectcolor2"></i>
                  <el-button type="text" class @click="addgood(tableData3)">添加商品</el-button>
                </div>
              </div>
              <div class v-show="(form.goodsType=='2' || form.goodsType=='3') && (form.useType.indexOf('2')>-1 || form.useType.indexOf('3')>-1)">
                <div>店内商品：</div>
                <el-scrollbar>
                  <div class="recordBox">
                    <el-table ref="multipleTable" :data="tableData4" tooltip-effect="dark" style="width: 100%" class="tablecenter">
                      <el-table-column prop="name" label="商品">
                        <template slot-scope="scope">
                          <div class="flex">
                            <div class="flex-g-0">
                              <el-image style="width: 60px;height: 60px;border-radius: 10px;" :src="scope.row.icon" fit="cover"></el-image>
                            </div>
                            <div class="flex-g-1 t_l">
                              <div class="mar_l10">{{scope.row.name}}</div>
                            </div>
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="price" label="价格"></el-table-column>
                      <el-table-column prop="stock" label="库存"></el-table-column>
                      <el-table-column label="操作">
                        <template slot-scope="scope">
                          <div class="textbutton">
                            <el-button size="mini" type="text" @click="open4(scope.row,scope.$index)" class>删除</el-button>
                          </div>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </el-scrollbar>
                <div class="addgoods textbutton">
                  <i class="el-icon-plus subjectcolor2"></i>
                  <el-button type="text" @click="addgood4(tableData4)">添加商品</el-button>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="选择商品" :required="true"  v-if="type=='3'">
              <div class v-show="form.useType.indexOf('1')>-1">
                <div>外卖商品：</div>
                <el-scrollbar>
                  <div class="recordBox">
                    <el-table ref="multipleTable" :data="tableData5" tooltip-effect="dark" style="width: 100%" class="tablecenter">
                      <el-table-column prop="name" label="商品">
                        <template slot-scope="scope">
                          <div class="flex">
                            <div class="flex-g-0">
                              <el-image style="width: 60px;height: 60px;border-radius: 10px;" :src="scope.row.icon" fit="cover"></el-image>
                            </div>
                            <div class="flex-g-1 t_l">
                              <div class="mar_l10">{{scope.row.name}}</div>
                            </div>
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="price" label="价格"></el-table-column>
                      <el-table-column prop="stock" label="库存"></el-table-column>
                      <el-table-column label="操作">
                        <template slot-scope="scope">
                          <div class="textbutton">
                            <el-button size="mini" type="text" @click="open5(scope.row,scope.$index)" class>删除</el-button>
                          </div>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </el-scrollbar>
                <div class="addgoods textbutton" v-if="tableData5.length<1">
                  <i class="el-icon-plus subjectcolor2"></i>
                  <el-button type="text" class @click="addgood5(tableData5)">添加商品</el-button>
                </div>
              </div>
              <div class v-show="(form.useType.indexOf('2')>-1 || form.useType.indexOf('3')>-1)">
                <div>店内商品：</div>
                <el-scrollbar>
                  <div class="recordBox">
                    <el-table ref="multipleTable" :data="tableData6" tooltip-effect="dark" style="width: 100%" class="tablecenter">
                      <el-table-column prop="name" label="商品">
                        <template slot-scope="scope">
                          <div class="flex">
                            <div class="flex-g-0">
                              <el-image style="width: 60px;height: 60px;border-radius: 10px;" :src="scope.row.icon" fit="cover"></el-image>
                            </div>
                            <div class="flex-g-1 t_l">
                              <div class="mar_l10">{{scope.row.name}}</div>
                            </div>
                          </div>
                        </template>
                      </el-table-column>
                      <el-table-column prop="price" label="价格"></el-table-column>
                      <el-table-column prop="stock" label="库存"></el-table-column>
                      <el-table-column label="操作">
                        <template slot-scope="scope">
                          <div class="textbutton">
                            <el-button size="mini" type="text" @click="open6(scope.row,scope.$index)" class>删除</el-button>
                          </div>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </el-scrollbar>
                <div class="addgoods textbutton" v-if="tableData6.length<1">
                  <i class="el-icon-plus subjectcolor2"></i>
                  <el-button type="text" @click="addgood6(tableData6)">添加商品</el-button>
                </div>
              </div>
            </el-form-item>
            <el-form-item label="适用场景" :required="true">
              <el-checkbox-group v-model="form.useType">
                <el-checkbox label="1">外卖</el-checkbox>
                <el-checkbox label="2">堂食</el-checkbox>
                <el-checkbox label="3">快餐</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="优惠券主题色" :required="true">
              <el-color-picker v-model="form.color"></el-color-picker>
            </el-form-item>
            <div class="shuju_title mar_b20">
              <div class="shuju_title_text">
                <span>基本规则</span>
              </div>
            </div>
            <el-form-item label="每人限领次数" :required="true">
              <div class="time_item">
                <el-radio v-model="form.isMax" label="1">不限次数</el-radio>
                <el-radio v-model="form.isMax" label="2">每人限领</el-radio>
                <span v-show="form.isMax=='2'">
                  <el-input-number v-model="form.maxNum" controls-position="right" :min="1" :max="1000000"></el-input-number>
                  <span class="mar_l10">张</span>
                </span>
              </div>
              <div class="yb_margin lh16">不限次数是指用户使用完后还可以继续领取</div>
            </el-form-item>
            <el-form-item label="领取人限制" :required="true">
              <el-radio-group v-model="form.memberType">
                <el-radio label="1">所有人均可领取</el-radio>
                <el-radio label="2">会员可领</el-radio>
                <el-radio label="3" v-show="form.storeType!='2'">指定标签用户可领</el-radio>
              </el-radio-group>
              <div class="mar_t10" v-show="form.memberType=='3' && form.storeType!='2'">
                <el-select v-model="memberLabel" clearable multiple filterable allow-create placeholder="请选择标签">
                  <el-option v-for="item in labelOptions" :key="item.id" :label="item.labelName" :value="item.id"></el-option>
                </el-select>
              </div>
            </el-form-item>
            <el-form-item label="使用时间" :required="true">
              <div>
                <el-radio v-model="form.timeType" label="1">固定日期</el-radio>
              </div>
              <div v-show="form.timeType=='1'" class="mar_b20">
                <el-date-picker v-model="timeData2" type="datetimerange" align="right" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['08:00:00', '23:59:59']"></el-date-picker>
              </div>
              <div class="time_item mar_t10 flex">
                <el-radio v-model="form.timeType" label="2">领券后</el-radio>
                <el-input-number v-model="form.day" v-if="form.timeType=='1'" disabled controls-position="right" :min="1" :max="1000000"></el-input-number>
                <el-input-number v-model="form.day" v-else controls-position="right" :min="1" :max="1000000"></el-input-number>
                <span class="mar_l10">日内有效</span>
                <div class="mar_l10 mar_t5" v-if="form.timeType=='2'">
                  <el-checkbox v-model="form.isNextDay" true-label="1" false-label="2">次日起</el-checkbox>
                </div>
              </div>
              <div class="yb_margin lh16">默认从今日起，如需次日有效请勾选次日起选项</div>
            </el-form-item>
            <el-form-item label="领券中心展示" :required="true">
              <el-radio-group v-model="form.display">
                <el-radio label="1">显示</el-radio>
                <el-radio label="2">隐藏</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="支持线下核销" :required="true">
              <el-radio-group v-model="form.isHx">
                <el-radio label="1">支持</el-radio>
                <el-radio label="2">不支持</el-radio>
              </el-radio-group>
              <div class="yb_margin lh16">启用后，该优惠券会附带一个二维码，可以使用店铺助手小程序直接核销使用</div>
            </el-form-item>
            <div class="shuju_title mar_b20">
              <div class="shuju_title_text">
                <span>使用说明</span>
              </div>
            </div>
            <el-form-item label="分享图片">
              <div class="uploadSource bor_de rel flex" v-if="form.shareImg">
                <label class="statusLabel curs" @mouseenter="enter(1)" @mouseleave="leave(1)">
                  <i class="el-icon-check" ref="imgicon1"></i>
                  <i class="el-icon-close" @click="deleteMultiImage(form.shareImg,1)"></i>
                </label>
                <img :src="form.shareImg" @click="test(1)" class="wid" />
              </div>
              <div class="uploadSource flex-center curs" v-else @click="test(1)">
                <i class="el-icon-plus fon_40 color_d9"></i>
              </div>
              <!--                            <div class="yb_margin">建议尺寸：1920×1080</div>-->
            </el-form-item>
            <el-form-item label="分享自定义标题">
              <el-input v-model="form.shareTitle" placeholder="请输入分享自定义标题"></el-input>
            </el-form-item>
            <el-form-item label="券说明">
              <baidu-ueditor :content="form.details" @ueditor="getUeditor"></baidu-ueditor>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
    <attachment-img ref="img1" type="img" @attachment="imgadd1"></attachment-img>
    <div class="mar_t20 ba_f pad_20 t_c">
      <el-button type="primary" @click="submitForm">立即创建</el-button>
    </div>
    <edit ref="edit" @fetchData="tableData" @fetchData2="tableData2"></edit>
    <edit2 ref="edit2" @fetchData="ftableData5" @fetchData2="ftableData6"></edit2>
    <shopEdit ref="ShopEdit" @fetchData="shopListData"></shopEdit>
  </div>
</template>
<script>
import { postSaveCoupon, getSaveCoupon } from '@/api/plug';
import { selectStore } from '@/api/shop';
import { changeDate } from '@/utils/index';
import baiduUeditor from '@/plugins/baidu-ueditor';
import attachmentImg from '@/plugins/attachment-img';
import Edit from './components/selectgood';
import Edit2 from './components/selectgood2';
import shopEdit from './components/selectshop';

export default {
  components: { baiduUeditor, attachmentImg, Edit, shopEdit ,Edit2},
  created() {
    this.init();
    if (this.$route.query.type) {
      this.type = this.$route.query.type;
      // this.edit()
    }
    if (this.$route.query.id) {
      this.id = this.$route.query.id;
      this.edit();
    }
  },
  data() {
    return {
      rules: {
        name: [
          { required: true, message: '请输入优惠券名称', trigger: 'blur' },
          { min: 2, max: 15, message: '长度在 2 到 15 个字符', trigger: 'blur' }
        ],
        time: [{ required: true, message: '请选择活动时间', trigger: 'blur' }]
        // total: [
        //     {required: true, message: '请填写发放总量', trigger: 'blur'}
        // ],
        // money: [
        //     {required: true, message: '请填写优惠内容', trigger: 'blur'}
        // ],
        // changjin: [
        //     {required: true, message: '请选择使用场景', trigger: 'blur'}
        // ]
      },
      type: '1',
      id: '',
      form: {
        sort: '1',
        name: '',
        isFull: '1',
        fullMoney: '',
        money: '',
        discount: '',
        timeType: '1',
        isNextDay: '1',
        useType: ['1'],
        goodsType: '1',
        memberType: '1',
        storeType: '1',
        details: '',
        stock: '1',
        maxNum: '',
        isMax: '1',
        shareImg: '',
        shareTitle: '',
        display: '1',
        isHx: '2',
        color: '#EE472B',
        subsidy: ''
      },
      goodsArr: [],
      goodsArr2: [],
      memberLabel: [],
      plugin: [],
      labelOptions: [],
      typeOptions: [],
      typeOptions2: [],
      radio2: '1',
      num2: '',
      timeData: [new Date(), new Date().setMonth(new Date().getMonth() + 3)],
      timeData2: [new Date(), new Date().setMonth(new Date().getMonth() + 3)],
      collapseName: '',

      tableData3: [],
      tableData4: [],
      tableData5: [],
      tableData6: [],
      yhtableData: [],
      dialogTableVisible4: false,
      goodName: '',

      shopTable: []
    };
  },
  methods: {
    tableData(tableData) {
      this.tableData3 = tableData;
      // if(this.tableData3){
      //     this.tableData3 = this.tableData3.concat(tableData)
      // }else {
      //     this.tableData3 = tableData
      // }
    },
    tableData2(tableData){
      this.tableData4 = tableData;
    },
    ftableData5(tableData){
      this.tableData5 = tableData;
    },
    ftableData6(tableData){
      this.tableData6 = tableData;
    },
    async shopListData(data) {
      this.shopTable = data ? data : [];
    },
    open1(row, index) {
      console.log('删除', row, index);
      this.$delete(this.tableData3, index);
    },
    open4(row, index) {
      this.$delete(this.tableData4, index);
    },
    open2(row, index) {
      this.$delete(this.shopTable, index);
    },
    open5(row, index) {
      this.$delete(this.tableData5, index);
    },
    open6(row, index) {
      this.$delete(this.tableData6, index);
    },
    enter(i = 0) {
      this.$refs['imgicon' + i].style.display = 'none';
    },
    leave(i = 0) {
      this.$refs['imgicon' + i].style.display = 'inline-block';
    },
    test(i = 0) {
      // console.log(this.$refs, i)
      this.$refs['img' + i].dialogVisible = true;
    },
    imgadd1(url) {
      this.form.shareImg = url.str;
    },
    deleteMultiImage(item, index, type) {
      Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
          this.splice(index, 1);
        }
      };
      if (type == 'multigraph') {
        switch (index) {
          case 2:
            this.form2.environment.remove(item);
            break;
        }
      } else {
        switch (index) {
          case 1:
            this.form.shareImg = '';
            break;
        }
      }
    },
    handleEdit(row) {
      if (row.id) {
        this.$refs['edit'].showEdit(row);
      } else {
        this.$refs['edit'].showEdit();
      }
    },
    getUeditor(content) {
      this.form.details = content;
    },
    async init() {
      const { data } = await getSaveCoupon();
      this.typeOptions = data.category ? data.category : [];
      this.typeOptions2 = data.instoreCategory ? data.instoreCategory : [];
      this.labelOptions = data.label ? data.label : [];
    },
    async edit() {
      const { data } = await getSaveCoupon({ id: this.id });
      this.form2 = this.form;
      this.form = Object.assign(this.form2, data);
      if (data.startTime) {
        this.timeData = [data.startTime, data.endTime];
      }
      if (data.useStartTime) {
        this.timeData2 = [data.useStartTime, data.useEndTime];
      }
      if (data.goodsType == '2' || data.goodsType == '3') {
        this.tableData3 = data.goodsArr ? data.goodsArr : [];
        this.tableData4 = data.goodsArr2 ? data.goodsArr2 : [];
      }
      if (data.goodsType == '4') {
        this.goodsArr = data.goodsArr ? data.goodsArr : [];
        this.goodsArr2 = data.goodsArr2 ? data.goodsArr2 : [];
      }
      if (data.memberType == '3') {
        this.memberLabel = data.memberLabel ? data.memberLabel : [];
      }
      if(this.type=='3'){
        this.tableData5 = data.goodsArr ? data.goodsArr : [];
        this.tableData6 = data.goodsArr2 ? data.goodsArr2 : [];
      }
      if (data.storeInfo) {
        this.shopTable = data.storeInfo ? data.storeInfo : [];
      }
      // if (data.reductionArr) {
      //     this.fullArr = data.reductionArr.map((v => ({fullMoney: v.fullMoney, money: v.money,isFree:v.isFree})))
      // }
    },
    addgood(row) {
      this.$refs['edit'].isGoodsInfo ('1');
      if (row) {
        const id = row.map((item) => item.id);
        this.$refs['edit'].showEdit(id);
      } else {
        this.$refs['edit'].showEdit();
      }
      this.$refs['edit'].isSpec('');
    },
    addgood4(row) {
      this.$refs['edit'].isGoodsInfo ('2');
      this.$refs['edit'].isSpec('2');
      if (row) {
        const id = row.map((item) => item.id);
        this.$refs['edit'].showEdit(id);
      } else {
        this.$refs['edit'].showEdit();
      }
    },
    addgood5(row) {
      this.$refs['edit2'].isGoodsInfo ('1');
      this.$refs['edit2'].isSpec('2');
      if (row) {
        const id = row.map((item) => item.id);
        this.$refs['edit2'].showEdit(id);
      } else {
        this.$refs['edit2'].showEdit();
      }
    },
    addgood6(row) {
      this.$refs['edit2'].isGoodsInfo ('2');
      this.$refs['edit2'].isSpec('2');
      if (row) {
        const id = row.map((item) => item.id);
        this.$refs['edit2'].showEdit(id);
      } else {
        this.$refs['edit2'].showEdit();
      }
    },
    addshop(row) {
      if (row) {
        const storeIds = row.map((item) => item.id);
        this.$refs['ShopEdit'].showEdit(storeIds);
      } else {
        this.$refs['ShopEdit'].showEdit();
      }
    },
    // async addgood(){
    //     this.dialogTableVisible4 = true;
    //     if(this.yhtableData.length<=0){
    //         res=await this.request({url:"{$_W['siteroot']}/app/index.php?i={$_W['uniacid']}&c=entry&do=GetStoreList&m={$_GPC['m']}"})
    //         console.log(res.data)
    //         res.data.forEach(item =>{
    //             item.edit = '选取'
    //             this.yhtableData.push(item)
    //         })
    //         for (let i = 0; i < this.yhtableData.length; i++) {
    //             for (let j = 0; j < this.tableData3.length; j++) {
    //                 if(this.tableData3[j].id === this.yhtableData[i].id){
    //                     this.yhtableData[i].edit='已选'
    //                     // newArr.push(this.tableData3[j]);
    //                 }
    //             }
    //         }
    //     }
    // },
    async submitForm() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          this.form.type = this.type;
          if (this.timeData) {
            this.form.startTime = changeDate(this.timeData[0]);
            this.form.endTime = changeDate(this.timeData[1]);
          }
          if (this.timeData2) {
            this.form.useStartTime = changeDate(this.timeData2[0]);
            this.form.useEndTime = changeDate(this.timeData2[1]);
          }
          if (this.form.goodsType == '2' || this.form.goodsType == '3') {
            if (this.tableData3) {
              this.form.goodsArr = this.tableData3.map((item) => item.id);
            }
            if (this.tableData4) {
              this.form.goodsArr2 = this.tableData4.map((item) => item.id);
            }
          }
          if (this.type == '3') {
            if (this.tableData5) {
              this.form.goodsArr = this.tableData5.map((item) => item.id);
            }
            if (this.tableData6) {
              this.form.goodsArr2 = this.tableData6.map((item) => item.id);
            }
            this.form.goodsType = '2'
          }
          if (this.form.goodsType == '4') {
            this.form.goodsArr = this.goodsArr;
            this.form.goodsArr2 = this.goodsArr2;
          }
          if (this.form.memberType == '3') {
            this.form.memberLabel = this.memberLabel;
          }
          if (this.shopTable) {
            this.form.storeArr = this.shopTable.map((item) => item.id);
          }
          const { msg } = await postSaveCoupon(this.form);
          this.$baseMessage(msg, 'success');
          // this.$router.go(-1)
          this.$router.push({ path: 'couponlist' });
        } else {
          return false;
        }
      });
    }
  }
};
</script>
<style lang="scss">
.recordBox {
  max-height: 600px;
}

.baiduUe {
  .time_item .el-input {
    width: 180px;
  }
}
</style>
